
Partial Class RIAssessments_LevelOfAssistanceMultiplier
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, _
                            ByVal e As System.EventArgs) _
                            Handles Me.Load

        Me.MessageLabel.Visible = False

        If Not Page.IsPostBack Then
            ' Initially load the activities drop down list and then load the grid based on the the selected
            ' activity.
            Me.ActivitiesDropDownList.DataSource = Cdm.RIDataCore.Assessments.AssessmentActivity.ListBySort("Description")
            Me.ActivitiesDropDownList.DataValueField = "AssessmentActivityId"
            Me.ActivitiesDropDownList.DataTextField = "Description"
            Me.ActivitiesDropDownList.DataBind()
            Me.BindGrid()
        End If

    End Sub

    Protected Sub ActivitiesDropDownList_SelectedIndexChanged(ByVal sender As Object, _
                                                              ByVal e As System.EventArgs) _
                                                              Handles ActivitiesDropDownList.SelectedIndexChanged

        BindGrid()

    End Sub

    Protected Sub BindGrid()

        Me.MultiplierGridView.DataSource = Cdm.RIDataCore.Assessments.LevelOfAssistanceMultiplierDisplay.ListByAssessmentActivityId(Me.ActivitiesDropDownList.SelectedValue, "LevelOfAssistance")
        Me.MultiplierGridView.DataBind()

    End Sub

    Protected Sub MultiplierGridView_RowCancelingEdit(ByVal sender As Object, _
                                                      ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) _
                                                      Handles MultiplierGridView.RowCancelingEdit

        Me.MultiplierGridView.EditIndex = -1
        Me.BindGrid()

    End Sub

    Protected Sub MultiplierGridView_RowEditing(ByVal sender As Object, _
                                                ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) _
                                                Handles MultiplierGridView.RowEditing

        Me.MultiplierGridView.EditIndex = e.NewEditIndex
        Me.BindGrid()

    End Sub

    Protected Sub MultiplierGridView_RowUpdating(ByVal sender As Object, _
                                                 ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) _
                                                 Handles MultiplierGridView.RowUpdating

        Dim multiplier As Double
        If IsNumeric(CType(Me.MultiplierGridView.Rows(e.RowIndex).Cells(1).Controls(0), TextBox).Text) Then

            Dim levelOfAssistanceMultiplier As Cdm.RIDataCore.Assessments.LevelOfAssistanceMultiplier
            levelOfAssistanceMultiplier = Cdm.RIDataCore.Assessments.LevelOfAssistanceMultiplier.Retrieve(CInt(Me.MultiplierGridView.DataKeys(e.RowIndex).Values(0)))
            multiplier = CDbl(CType(Me.MultiplierGridView.Rows(e.RowIndex).Cells(1).Controls(0), TextBox).Text)
            levelOfAssistanceMultiplier.Multiplier = multiplier
            levelOfAssistanceMultiplier.Persist()
            Me.MultiplierGridView.EditIndex = -1
            Me.BindGrid()

        Else

            Me.ShowMessage("You must enter a numeric value for multiplier.", Drawing.Color.Firebrick)

        End If

    End Sub

    Protected Sub ShowMessage(ByVal message As String, ByVal foreColor As System.Drawing.Color)

        Me.MessageLabel.ForeColor = foreColor
        Me.MessageLabel.Text = message
        Me.MessageLabel.Visible = True

    End Sub

End Class
